package lk.service.blogspringboot.service.impl;

import lk.service.blogspringboot.domain.ArticleVersion;
import lk.service.blogspringboot.mapper.ArticleVersionMapper;
import lk.service.blogspringboot.service.ArticleVersionService;
import lk.service.blogspringboot.util.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 文章版本表(ArticleVersion)表服务实现类
 *
 * @author LK
 * @since 2024-08-22 10:33:42
 */
@Service("articleVersionService")
public class ArticleVersionServiceImpl implements ArticleVersionService {
    @Resource
    private ArticleVersionMapper articleVersionMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param versionId 主键
     * @return 实例对象
     */
    @Override
    public R queryById(Integer versionId) {
        return R.ok().setData(this.articleVersionMapper.queryById(versionId));
    }

    /**
     * 全查询
     *
     * @param articleVersion 筛选条件
     * @return 查询结果
     */
    @Override
    public R queryAll(ArticleVersion articleVersion) {
        return R.ok().setData(this.articleVersionMapper.queryAll(articleVersion));
    }

    /**
     * 新增数据
     *
     * @param articleVersion 实例对象
     * @return 实例对象
     */
    @Override
    public R insert(ArticleVersion articleVersion) {
        this.articleVersionMapper.insert(articleVersion);
        return R.ok().setData(articleVersion);
    }

    /**
     * 修改数据
     *
     * @param articleVersion 实例对象
     * @return 实例对象
     */
    @Override
    public R update(ArticleVersion articleVersion) {
        this.articleVersionMapper.update(articleVersion);
        return R.ok().setData(this.queryById(articleVersion.getVersionId()));
    }

    /**
     * 通过主键删除数据
     *
     * @param versionId 主键
     * @return 是否成功
     */
    @Override
    public R deleteById(Integer versionId) {
        boolean del = this.articleVersionMapper.deleteById(versionId) > 0;
        return R.ok().setData(del);
    }
}

